#include "scene_camera.h"

USING_NS_CC;

void SceneCamera::lookAt(const cocos2d::Point& position)
{
    _position = position;
    convertPosition(_position);
}

void SceneCamera::convertPosition(cocos2d::Point& position)
{
    float minX = _viewableRange.getMinX();
    float minY = _viewableRange.getMinY();
    float maxX = _viewableRange.getMaxX();
    float maxY = _viewableRange.getMaxY();

    if ( minX != maxX && minY != maxY )
    {
        position.x = position.x < minX ? minX : position.x;
        position.y = position.y < minY ? minY : position.y;
        position.x = position.x > maxX - _viewSize.width ? maxX - _viewSize.width : position.x;
        position.y = position.y > maxY - _viewSize.height ? maxY - _viewSize.height : position.y;
    }
}
